require 'stream/cons'

module Lisp

  class DeferredPair < Pair
    def initialize(head, &tail)
      raise RuntimeError.new("tail required") unless block_given?
      super(head, tail)
    end

    def tail
      DeferredPair.new(@tail.call(head), &@tail)
    end
  end

  def stream(head, &tail)
    DeferredPair.new(head, &tail)
  end

=begin
  def stream_null?(stream)
    stream.stream_null?
  end

  def stream_filter(predicate, stream)
    return the_empty_stream if stream_null? stream
    return cons_stream(stream_car(stream), stream_filter(predicate, stream_cdr(stream))) if predicate.call(head)
    return stream_filter(predicate, stream_cdr(stream))
  end

  def stream_for_each(action, stream)
    return if stream_null? stream
    action.call(stream_car(stream))
    stream_for_each(action, stream_cdr(stream))
  end

  def display_stream(stream)
    stream_for_each(lambda{|x| puts x}, stream)
  end
=end
end

=begin
class Array
  alias :stream_null? :empty?
end
=end
